﻿using Ledict.ConditionExtract.Authority;
using Ledict.ConditionExtract.Base;
using Ledict.ConditionExtract.BLL;
using Ledict.Utility.Msg;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ledict.ConditionExtract.Frm
{
    /// <summary>
    /// 修改密码
    /// </summary>
    public partial class FrmUpdatePassWord : BaseForm
    {
        CoreUserBLL coreUserBll = new CoreUserBLL();
        public FrmUpdatePassWord()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 取消按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void colBtnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        /// <summary>
        /// 确定按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void colBtnOk_Click(object sender, EventArgs e)
        {
            try
            {
                if(string.IsNullOrEmpty(colTxtOldPass.Text))
                {
                    MsgBox.Warn("请输入旧密码！");
                    colTxtOldPass.Focus();
                    return;
                }
                if (colTxtOldPass.Text!= Gvar.uo.m_loginPassWord)
                {
                    MsgBox.Warn("旧密码输入错误！");
                    colTxtOldPass.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(colTxtPassWord.Text))
                {
                    MsgBox.Warn("请输入密码！");
                    colTxtPassWord.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(colTxtPassWordAgain.Text))
                {
                    MsgBox.Warn("请再次输入密码！");
                    colTxtPassWordAgain.Focus();
                    return;
                }
                if (colTxtPassWord.Text != colTxtPassWordAgain.Text)
                {
                    MsgBox.Warn("两次密码输入不一致，请重新输入！");
                    colTxtPassWord.Focus();
                    return;
                }
                AuthorityClient ac = new AuthorityClient();

                if (ac.UpdatePass(Gvar.uo.m_userId, colTxtPassWord.Text))
                {
                    MsgBox.OK("修改成功！");
                    Close();
                }
                else
                {
                    MsgBox.Warn("修改失败！");
                }
            }
            catch (Exception ex)
            {
                MsgBox.Err("发生错误：" + ex.Message);
            }
        }
    }
}
